package com.buss.product.model;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.buss.core.utils.StringUtil;

@Entity
@Table(name="base_goodsprop")
@TableGenerator(name="goodsprop_pk_sequence",initialValue=1,allocationSize=1,pkColumnName="seq_col",
pkColumnValue="goodsprop_seq",valueColumnName="seq_val",table="product_pk_sequence")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@JsonIgnoreProperties(value={"goods","cateProp"})
public class GoodsProp implements Serializable {
	
	private static final long serialVersionUID = 4962993513050921130L;
	
	/**商品属性ID*/
	@Id
	@GeneratedValue(strategy=GenerationType.TABLE,generator="goodsprop_pk_sequence")
	private Long id;
	
	/**
	 * 商品信息
	 */
	@ManyToOne(cascade = CascadeType.REFRESH,fetch=FetchType.LAZY,optional=true)
	@JoinColumn(name = "goodsId",nullable = false)
	private Goods goods;
	
	/**分类属性编码*/
	@ManyToOne(cascade=CascadeType.REFRESH,fetch=FetchType.EAGER)
	@JoinColumn(name="catepropId",nullable=false)
	private CateProp cateProp;
	
	/**属性值*/
	@Column(length=500)
	private String propValue;

	@Transient
	public String[] propValueArr;
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Goods getGoods() {
		return goods;
	}

	public void setGoods(Goods goods) {
		this.goods = goods;
	}

	public CateProp getCateProp() {
		return cateProp;
	}

	public void setCateProp(CateProp cateProp) {
		this.cateProp = cateProp;
	}

	public String getPropValue() {
		return propValue;
	}

	public void setPropValue(String propValue) {
		this.propValue = propValue;
	}

	public String[] getPropValueArr() {
		String[] values = getPropValue().split("\n");
		return values;
	}

	public void setPropValueArr(String[] propValueArr) {
		this.propValueArr = propValueArr;
		setPropValue(StringUtil.join(propValueArr, "\n"));
	}
	
	public static void main(String[] args){
		
	}
}
